
(*
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$
$$$   PASCAL FILE NAME .................... TK.PART3.TEXT
$$$   PASCAL FILE TYPE .................... TEXT
$$$   PASCAL FILE DATE .................... 1985-MAY-31
$$$
$$$   PASCAL VOLUME NAME .................. TK
$$$
$$$   DISK IMAGE NAME ..................... A2PASDT1
$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$
$$$   DISK IMAGE COMMENT:
$$$
$$$     APPLE II PASCAL DESKTOP TOOLKIT - MOUSE GRAPHICS - 1988 - 1/4
$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
*)



 procedure LoadFont;
    const
       FontSize = 3;    { Num blocks used by the font. }
    var
       NoRead
         : integer;
          
          
          procedure FontMemory;
          { Allocates some memory on the heap for the font.}
          { Is called before the font is loaded. }
          
              var
                 heap
                   : ^integer;
                 memblock
                   : ^charblock;
                 blocknumber
                   : integer;
              begin { FontMemory }
                 mark(heap);
                 moveleft(heap, PtrToFont, 2);
                 for blocknumber:= 1 to FontSize do
                    new(memblock);
              end; { of FontMemory }
    
    begin { LoadFont }
       FontMemory;
       reset(tempfile, 'test.font');
       moveleft(PtrToFont, PtrToData, 2);
       NoRead:= blockread(tempfile, PtrToData^, FontSize, 0);
       close(tempfile);
    end; { of LoadFont }

procedure Initialize;

{ This one procedure initializes all the data structures 
{ used by the tool kit.  If code space is limited this 
{ whole procedure can be segmented and only loaded at
{ the beginning of the run. }

      var
         menu_index,
         title_index
           : integer;
      
      { Sets up the menu identified by Menu_Index.  Sets the MenuID, 
        Disable flag, title pointer, and pointer to menu data. }
      procedure InitTitle (menu_index : integer);
         begin { InitTitle }
            with a_menubar.menus[menu_index] do
               begin
                  menu_id:= menu_index;
                  disabled:= 0;
                  pointer:= PointerTo(MTitle[menuindex]);
                  moveleft(pointer, title_ptr, 2);
                  pointer:= PointerTo(MData[menuindex]);
                  moveleft(pointer, m_data_ptr, 2);
               end; { with }
         end; { of InitTitle }
         
      procedure InitStrings;
         { This procedure puts all the string constants into
         { their respective arrays. }
         procedure Part1;
             begin
                
                WTitle[1]:= 'A Small Window';
                WTitle[2]:= 'A Big Window';
                WTitle[3]:= 'Font Display';
                WTitle[4]:= 'Test Window';
                WTitle[5]:= 'Dialog';
                
                
                {$R-}
                MTitle[1]:= '?';
                MTitle[1,1] := chr(30); { the apple char in my font.}
                {$R+}
                
                   AppleItem[1]:= 'What''s it all about?';
                
                MTitle[file_menu]:= 'File';
                   FileItem[1]:= 'Quit';
                
                MTitle[edit_menu]:= 'Edit';
                   EditItem[1]:= 'Undo';
                   {Item 2 is filler}
                   EditItem[3]:= 'Cut';
                   EditItem[4]:= 'Copy';
                   EditItem[5]:= 'Paste';
                   
                MTitle[Window_Menu] := 'Windows';
                  WindowItem[1] := 'Small Window';
                  WindowItem[2] := 'Large Window';
                  WindowItem[3] := 'Font Display';
                  { 4 is filler }
                  WindowItem[5] := 'Drag';
                  WindowItem[6] := 'Grow';
                  WindowItem[7] := 'Hide';
                
                MTitle[MTest_Menu] := 'Menu Test';
                  MTItem[1] := 'Clear Menu';
                  MTItem[2] := 'Disable Menu';
                  MTItem[3] := 'Enable Menu';
                  MTItem[4] := 'Disable Items';
                  MTItem[5] := 'Enable Items';
                  MTItem[6] := 'Check Items';
                  MTItem[7] := 'Uncheck Items';
                  MTItem[8] := 'Change Some Marks';
                  MTItem[9] := 'Restore Some Marks';
              end;
          procedure part2;
              begin
              
                MTitle[WTest_Menu] := 'Window Test';
                  WTItem[1] := 'Open Window';
                  WTItem[2] := 'Dialog';
                  WTItem[3] := 'Go Away Present';
                  WTItem[4] := 'H-Scroll Present';
                  WTItem[5] := 'V-Scroll Present';
                  WTItem[6] := 'H-Thumb Present';
                  WTItem[7] := 'V-Thumb Present';
                  WTItem[8] := 'H-Scroll Active';
                  WTItem[9] := 'V-Scroll Active';
                  WTItem[10] := 'Grow Box Present';
                
                MTitle[Dummy_Menu] := 'Dummy';
                  DummyItem[1] := 'Item 1';
                  DummyItem[2] := 'Item 2';
                  DummyItem[3] := 'Item 3';
                  DummyItem[4] := 'Item 4';
                  
                  { Filler }
                  
                  DummyItem[6] := 'Item 6';
                  DummyItem[7] := 'Item 7';
                  DummyItem[8] := 'Item 8 and more text';
                  DummyItem[9] := 'Item 9';
                  DummyItem[10] := 'Item 10';
                
             end;
         begin
           part1;
           part2;
         end; { of InitString }
             
      { Copys the master winfo (winfo[0]) into the desired winfo and
        sets the new winfos id to that which is passed. }
      procedure NewWinfo(nextwindow: integer);
         begin { NewWinfo }
            a_winfo[nextwindow]:= a_winfo[0];
            with a_winfo[nextwindow] do
               window_id:= nextwindow;
         end; { of NewWinfo }
      
      procedure InitWinfos;
         begin { InitWinfo }
            
            with a_winfo[0] do
               begin
                  
                  growbox:= true;
                  goawaybox:= true;
                  dialog:= false;
                  
                  hscrollbar:= true;
                  hthumb:= false;
                  hactive:= false;
                  
                  vscrollbar:= true;
                  vthumb:= false;
                  vactive:= false;
                  
                  hthumbpos:= 0;
                  vthumbpos:= 0;
                  
                  hthumbmax:= 255;
                  vthumbmax:= 255;
               
                  mincontwidth:= 100;
                  mincontlength:= 50;
                  maxcontwidth:= 500;
                  maxcontlength:= 190;
                  with windowport do
                     begin
                        with portmap do
                           begin
                              viewloc.x:= 100;
                              viewloc.y:=  30;
                              mapbits:= 8192;
                              mapwidth:= 128;
                              maprect.topleft.x:= 0;
                              maprect.topleft.y:= 0;
                              maprect.botright.x:= 300;
                              maprect.botright.y:= 150;
                           end; { with }
                        colormasks.andmask := 255;
                        colormasks.ormask := 0;
                        penloc.x:= 0;
                        penloc.y:= 0;
                        penwidth:= 1;
                        penheight:= 1;
                        penmode:= pencopy;
                        textback:= 127;
                        textfont:= PtrToFont;
                     end; { with }
                  
               end; { with }
                
            NewWinfo(small_id);
            with a_winfo[small_id] do
               begin
                  pointer:= PointerTo(WTitle[small_id]);
                  moveleft(pointer, title_ptr, 2);
                  
                      mincontwidth:= 100;
                      mincontlength:= 50;
                      maxcontwidth:= 300;
                      maxcontlength:= 150;
                    
                  with a_winfo[small_id].windowport.portmap do
                     begin
                       viewloc.x:= 250;
                       viewloc.y:=  50;
                       maprect.topleft.x:= 0;
                       maprect.topleft.y:= 0;
                       maprect.botright.x:= 200;
                       maprect.botright.y:= 100;
                     end; { with }
               end; { with }
                     
            NewWinfo(big_id);
            with a_winfo[big_id] do
               begin
                  pointer:= PointerTo(WTitle[big_id]);
                  moveleft(pointer, title_ptr, 2);
                      
                      mincontwidth:= 100;
                      mincontlength:= 50;
                      maxcontwidth:= 500;
                      maxcontlength:= 190;
                    
                  with a_winfo[big_id].windowport.portmap do
                     begin
                       viewloc.x:= 50;
                       viewloc.y:= 50;
                       maprect.topleft.x:= 0;
                       maprect.topleft.y:= 0;
                       maprect.botright.x:= 400;
                       maprect.botright.y:= 110;
                     end; { with }
               end; { with }
            
            NewWinfo(chars_id);
            with a_winfo[chars_id] do
               begin
                  pointer:= PointerTo(WTitle[chars_id]);
                  moveleft(pointer, title_ptr, 2);
                  
                  growbox:= false;
                  goawaybox:= true;
                  dialog:= false;
                  
                  hscrollbar:= false;
                  hthumb:= false;
                  hactive:= false;
                  
                  vscrollbar:= false;
                  vthumb:= false;
                  vactive:= false;
                  
                  with a_winfo[chars_id].windowport.portmap do
                     begin
                       viewloc.x:= 20;
                       viewloc.y:= 120;
                       maprect.topleft.x:= 0;
                       maprect.topleft.y:= 0;
                       maprect.botright.x:= 170;
                       maprect.botright.y:= 90;
                     end; { with }
               end; { with }
            
            NewWinfo(test_id);
            with a_winfo[test_id] do
               begin
                  pointer:= PointerTo(WTitle[test_id]);
                  moveleft(pointer, title_ptr, 2);
                  
                      mincontwidth:= 50;
                      mincontlength:= 25;
                      maxcontwidth:= 500;
                      maxcontlength:= 185;
                    
                  with a_winfo[test_id].windowport.portmap do
                     begin
                       viewloc.x:= 20;
                       viewloc.y:= 120;
                       maprect.topleft.x:= 0;
                       maprect.topleft.y:= 0;
                       maprect.botright.x:= 400;
                       maprect.botright.y:= 150;
                     end; { with }
               end; { with }
            
            NewWinfo(Dialog_id);
            with a_winfo[dialog_id] do
               begin
                  pointer:= PointerTo(WTitle[dialog_id]);
                  moveleft(pointer, title_ptr, 2);
                  
                  growbox:= false;
                  goawaybox:= false;
                  dialog:= true;
                  
                  hscrollbar:= false;
                  hthumb:= false;
                  hactive:= false;
                  
                  vscrollbar:= false;
                  vthumb:= false;
                  vactive:= false;
                  
                  with a_winfo[dialog_id].windowport.portmap do
                     begin
                       viewloc.x:= 180;
                       viewloc.y:= 30;
                       maprect.topleft.x:= 0;
                       maprect.topleft.y:= 0;
                       maprect.botright.x:= 200;
                       maprect.botright.y:= 100;
                     end; { with }
               end; { with }
            
         end; { of InitWinfo }

      begin { Initialize }
         space:= ' ';
         
         nextwindow:= 0;
         windowid:= 0;
         
         fillchar(whicharea, sizeof(whicharea), 0);
         fillchar(a_menubar, sizeof(a_menubar), 0);
         fillchar(MData, sizeof(MData), 0);
         fillchar(MTitle, sizeof(MTitle), 0);
         fillchar(WTitle, sizeof(WTitle), 0);
         fillchar(AppleItem, sizeof(AppleItem), 0);
         fillchar(FileItem, sizeof(FileItem), 0);
         fillchar(EditItem, sizeof(EditItem), 0);
         fillchar(a_winfo, sizeof(a_winfo), 0);
         
         LoadFont;
         
         InitWinfos;
         InitStrings;
         
         with a_menubar do
            begin
               {Set menu titles and data pointers}
               num_menus:= 7;
               for menu_index:= 1 to num_menus do
                  InitTitle (menu_index);
               
               { For each menu we set the item pointers.  For
                 those items that are special, we set them after
                 the pointers are set up.  Note that we rely on
                 the zeroing of the data structures (above) to 
                 intialize the untouched variables. }
               
               {Apple menu}
               with MData[Apple_Menu] do
                  begin
                     num_items:= 1;
                     {point to AppleItem string}
                     pointer:= PointerTo(AppleItem[1]);
                     moveleft(pointer, items[1].item_str_ptr, 2);
                  end; { with }
               
               {File menu}
               with MData[file_menu] do
                  begin
                     num_items:= 1;
                     {point to FileItem strings}
                     for title_index:= 1 to num_items do
                        begin
                           pointer:= PointerTo(FileItem[title_index]);
                           moveleft(pointer, items[title_index].item_str_ptr,
                                    2);
                        end; { for }
                     
                     {line 4 is filler}
                     with items[4] do
                        begin
                           item_is_filler:= true;
                           item_str_ptr:= nil;
                        end; { with }
                  
                     {line 5 has a menu key}
                     with items[5] do
                        begin
                           solid_apple:= true;
                           open_apple:= true;
                           char1:= ord('Q');
                           char2:= ord('q');
                        end; { with }
               
                     
                  end; { with }
                     
               {Edit menu}
               with MData[edit_menu] do
                  begin
                     num_items:= 5;
                     {Point to EditItem strings}
                     for title_index:= 1 to num_items do
                        begin
                           pointer:= PointerTo(EditItem[title_index]);
                           moveleft(pointer, items[title_index].item_str_ptr,
                                    2);
                        end; { for }
                     
                     {line 2 is filler}
                     with items[2] do
                        begin
                           item_is_filler:= true;
                           item_str_ptr:= nil;
                        end; { with }
                  
                     {line 3 has a menu key}
                     with items[3] do
                        begin
                           solid_apple:= true;
                           open_apple:= true;
                           char1:= ord('X');
                           char2:= ord('x');
                        end; { with }
                     
                     {line 4 has a menu key}
                     with items[4] do
                        begin
                           solid_apple:= true;
                           open_apple:= true;
                           char1:= ord('C');
                           char2:= ord('c');
                        end; { with }
                     
                     {line 5 has a menu key}
                     with items[5] do
                        begin
                           solid_apple:= true;
                           open_apple:= true;
                           char1:= ord('V');
                           char2:= ord('v');
                        end; { with }
               
                  end; { with }
               
               {Windows menu}
               with MData[Window_menu] do
                  begin
                     num_items:= 7;
                     {Point to EditItem strings}
                     for title_index:= 1 to num_items do
                        begin
                           pointer:= PointerTo(WindowItem[title_index]);
                           moveleft(pointer, items[title_index].item_str_ptr,
                                    2);
                        end; { for }
                     
                     {line 4 is filler}
                     with items[4] do
                        begin
                           item_is_filler:= true;
                           item_str_ptr:= nil;
                        end; { with }
                  
                     {line 5 has a menu key}
                     with items[5] do
                        begin
                           solid_apple:= true;
                           open_apple:= true;
                           char1:= ord('D');
                           char2:= ord('d');
                        end; { with }
                     
                     {line 6 has a menu key}
                     with items[6] do
                        begin
                           solid_apple:= true;
                           open_apple:= true;
                           char1:= ord('G');
                           char2:= ord('g');
                        end; { with }
                     
                     {line 7 has a menu key}
                     with items[7] do
                        begin
                           solid_apple:= true;
                           open_apple:= true;
                           char1:= ord('H');
                           char2:= ord('h');
                        end; { with }
               
                  end; { with }
               
               
               {Menu Test Menu}
               with MData[MTest_Menu] do
                  begin
                     num_items:= 9;
                     {point to FileItem strings}
                     for title_index:= 1 to num_items do
                        begin
                           pointer:= PointerTo(MTItem[title_index]);
                           moveleft(pointer, items[title_index].item_str_ptr,
                                    2);
                        end; { for }
                     
                  end; { with }
          
               {Window Test Menu}
               with MData[WTest_Menu] do
                  begin
                     num_items:= 10;
                     {point to FileItem strings}
                     for title_index:= 1 to num_items do
                        begin
                           pointer:= PointerTo(WTItem[title_index]);
                           moveleft(pointer, items[title_index].item_str_ptr,
                                    2);
                        end; { for }
                     
                  end; { with }
          
               {Dummy Menu}
               with MData[dummy_menu] do
                  begin
                     num_items:= 10;
                     {point to FileItem strings}
                     for title_index:= 1 to num_items do
                        begin
                           pointer:= PointerTo(DummyItem[title_index]);
                           moveleft(pointer, items[title_index].item_str_ptr,
                                    2);
                        end; { for }
                     
                     {line 5 is filler}
                     with items[5] do
                        begin
                           item_is_filler:= true;
                           item_str_ptr:= nil;
                        end; { with }
                     
                  end; { with }
          
          
          
          end; { with }
                     
                     
      end; { of Initialize }
      
{ This is a proc to turn four integers into a rect variable requiried by
  paint, frame and in RECT. }
procedure  MakeRect (var r : rect; a,b,c,d : integer);
    begin
      r.left := a;
      r.top := b;
      r.right := c;
      r.bottom := d;
    end;

{ The following four procedures are used to handle window display.  They
  are:
  
                DrawIt
                DrawItB
                HandleUpdate
                ClearUpdates
                
  DrawIt is the procedure which actually does the drawing after the port
  is set.  It is called by both HandleUpdate and DrawItB.  HandleUpdate
  is called to handle any update event.  It starts by making the tool kit
  call BeginUpdate which sets the right port.  DrawItB can be called from
  anywhere in the program to refresh the top window.  It gets the window's
  port by making the tool kit call GetWinPort and then sets the port to
  that port before calling DrawIt.  ClearUpdates is used to clear any 
  updates in the event queue.  It peeks events in the queue and if it is
  an update event, it calls HandleUpdate.
  
 }
 
 
procedure  DrawIt (which_window : integer);
    const
       title_const = 'The Mouse Graphics Tool Kit';
       
    var
        j,k : integer;
        temp : string[1];
        r : rect;
        p : integer;
        p_ref : ^grafport;
    begin
      case which_window of
        
        small_id : 
          begin
            moveto (100,10);
            lineto (10,100);
            makerect(r,10,10,90,90);
            paintrect(r);
          end;
        
        big_id : 
          begin
            moveto (100,10);
            lineto (10,100);
            makerect(r,10,10,50,50);
            framerect(r);
            makerect(r,40,30,70,80);
            framerect(r);
          end;
        
        chars_id: 
          begin
            temp := ' ';
            for k := 0 to 7 do
              for j := 0 to 15 do 
                begin
                  moveto(5+j*10,15+k * 10);
                  temp[1] := chr(j+k*16);
                  drawtext(temp);
                end;
          end;
          
        test_id : 
          begin
            disp_winfo(5,10,a_winfo[test_id]);
          end;
                  
        dialog_id : 
          begin
            moveto(20,14);
            drawtext(Title_Const);
            moveto(20,14);
            line(textwidth(title_const),0);
            
            moveto(15,34);
            drawtext('This is a program to test');
            moveto(15,44);
            drawtext('test the many features of');
            moveto(15,54);
            drawtext('the Mouse Graphics Tool Kit.');
            moveto(15,64);
            drawtext('It also demonstrates how to');
            moveto(15,74);
            drawtext('use the tool kit.');
            moveto(15,94);
            drawtext('Click in this window to continue.');
          end;
          
      end; {case}
    
    end;



procedure  DrawItB  (which_window : integer);
    var
         p : pattern;
    
    begin
      { Tell toolkit to put right port in mainport }
      GetWinPort(which_window,mainport);
      
      { Set port to main port }
      SetPort(mainport);
      
      { Now redraw the appropriate window }
      DrawIt(which_window);
    end;


procedure  HandleUpdate     (which_window : integer);
        begin
          { Tell toolkit we are about to do it }
          BeginUpdate(which_window);
          
          if IOResult <> 0 then 
            begin
              exit(HandleUpdate); 
            end;
          
                                {This is important to 
                                 catch the case where the 
                                 window does not really 
                                 need to be updated.
                                 
                                 If you leave this out the
                                 tool kit will draw window
                                 contents at strange locations
                                 on the screen. }
          
          { Now do it }
          DrawIt(which_window);
          
          { Tell Toolkit that we are done }
          EndUpdate;
        end;



procedure  ClearUpdates;
    begin
      repeat
        PeekEvent(event);
        if event.evt_kind = update_event then
          begin
            GetEvent(event);
            HandleUpdate(event.char1);
          end;
      until event.evt_kind <> update_event;
    end;
    
    
   { I'm not yet sure what any of this does and what is 
     needed. }
   procedure InitMouseDriver;
      var
          {Mouse driver communications data}
          ErrorCode
            : integer;
          
          MouseMode: record
             IntMode: integer;
             IntAddr: integer;
             end;
             
          RequestCode: packed record
             Direction: 0..1;
             Stat_Ctrl: 0..1;
             Reserved: 0..2047;
             Code: 0..7;
             end;
       
      procedure InitInterrupts;
         begin { InitInterrupts }
            (*
            {Set the attach driver's interrupt address:
             UnitStatus Control code 0.}
            with RequestCode do
               begin
                  Direction:= 0;
                  Stat_Ctrl:= 1;
                  Code:= 0;
               end; { with }
            with MouseMode do
               begin
                  IntMode:= 0; { passive mode for now; if interrupts are
                                 required, StartDeskTop will enable them }
                  PascIntAdr(IntAddr);
               end; { with }
            UnitStatus(131, MouseMode, RequestCode);
            ErrorCode:= IOResult;
            if ErrorCode<> 0 then
               begin
                  WriteLn('SetMouse error: ', ErrorCode);
                  exit(psample);
               end; { if }
            *)
         end; { of InitInterrupts }
     
      begin { InitMouseDriver }
        {Start with the mouse off}
        UnitClear(131);
        ErrorCode:= IOResult;
        if ErrorCode<> 0 then
           begin
              if ErrorCode= 9 then
                 writeln('No mouse card installed.')
              else
                 writeln('UnitClear error: ', ErrorCode);
              exit(psample);
           end; { if }
     
        {InitInterrupts;}
        
     end; { of InitMouseDriver }
     
     
procedure StartItUp;
    begin { StartItUp }
       MouseSlot:= 0;
       use_interrupts:= false;
       pointer:= 4096;
       
       StartDeskTop(6, 234,         {Apple //c, Apple //e}
                    MouseSlot,      {search slots for the mouse}
                    use_interrupts, {passive= false; interrupts= true}
                    PtrToFont,      {pointer to system font}
                    pointer,        {menu save area}
                    4000);          {save area size}
                    
       SetKeyEvent(true);
       
       FlushEvents;
    
       SetMenu(a_menubar);
       ShowCursor;
    end; { of InitDeskTop }
    
      
      
procedure NewWindow(nextwindow: integer);
    var
        OldTop : integer;
    begin { NewWindow }
      FrontWindow(OldTop);
      if OldTop <> 0 then
         CheckItem(menu_id, OldTop, false);
      CheckItem(menu_id, menu_choice, true);
      OpenWindow(a_winfo[nextwindow]);
      
      DrawItB(menu_choice);
    end; { of NewWindow }
      
procedure DoApple;
    var
       event : type_event;
       screenx, screeny : integer;
       wheremouse : type_area;
       windowid : integer;
    
    begin
      fillchar(wheremouse, sizeof(wheremouse), 0);
      
      OpenWindow(a_winfo[dialog_id]);
      DrawItB(dialog_id);
      repeat
        getevent(event);
        
        if event.evt_kind = button_down then
          begin
            with event do
              begin
                screenx:= char1+ 256* char2;
                screeny:= char3+ 256* char4;
                FindWindow(screenx, screeny, wheremouse, windowid);
              end;
          end;
      until ((event.evt_kind = button_down) and 
            (wheremouse = in_content) and
            (windowid = Dialog_ID))
               
               or
               
            (event.evt_kind = key_down);
        
      CloseWindow(Dialog_ID);

    end;

procedure BringItUp (ThisOne : integer);
    begin
      FrontWindow(topwindow);
      if topwindow <> ThisOne then
         begin
            CheckItem(Window_Menu,TopWindow,false); { Uncheck current top }
            SelectWindow(ThisOne);
            DrawItB(ThisOne);
            CheckItem(Window_Menu,ThisOne,true);  { Check new top }
         end;
    end;
    
procedure DoContent;
   { This proc will do more when I do scrolling. }
   begin
      BringItUp(WindowID);
   end; { of DoContent }

         
procedure DoDrag;
    var
        ItMoved : boolean;
    begin
      DragWindow(windowid, screenx, screeny,ItMoved);
      
      if ItMoved then
          Clear_Updates;
    end;

procedure DoGrow;
    var
       ItGrew : boolean;
    begin
      GrowWindow(windowid, screenx, screeny,ItGrew);
    end;
    
procedure DoHide;
    var
       NewTop : integer;
       
    begin
      CloseWindow(windowid);
      CheckItem(window_menu,windowid, false);
      FrontWindow(NewTop);
      if NewTop <> 0 then 
        CheckItem(window_menu,NewTop, true);
    end; 
    
    
procedure DoWindows;
    begin 
      If menu_choice <= 3 then
        begin
          if a_winfo[menu_choice].WinOpen then BringItUp(menu_choice)
          else NewWindow(menu_choice);
        end
      else 
        if menu_choice in [5..7] then
        case menu_choice of
          5 : begin
                FakeMouse;
                FrontWindow(WindowId);  { DoDrag uses WindowID so set it
                                          to the top window }
                DoDrag;
              end;
          6 : begin
                FakeMouse;
                FrontWindow(WindowId);  { DoGrow uses WindowID so set it
                                          to the top window }
                DoGrow;
              end;
          7 : begin
                FrontWindow(WindowId);  { DoHide uses WindowID so set it
                                          to the top window }
                DoHide;
              end;
        end; {case}
    end; 
      
procedure doFile;
    begin { doFile }
      If menu_choice = 1 then
         QuitSelected:= true;
    end; { of doFile }
      
procedure doEdit;
    begin
    end;
   
procedure   SetChecks;
    begin
      CheckItem(WTest_Menu,2,a_winfo[test_id].dialog);
      CheckItem(WTest_Menu,3,a_winfo[test_id].GoAwayBox);
      CheckItem(WTest_Menu,4,a_winfo[test_id].hscrollbar);
      CheckItem(WTest_Menu,5,a_winfo[test_id].vscrollbar);
      CheckItem(WTest_Menu,6,a_winfo[test_id].hthumb);
      CheckItem(WTest_Menu,7,a_winfo[test_id].vthumb);
      CheckItem(WTest_Menu,8,a_winfo[test_id].hactive);
      CheckItem(WTest_Menu,9,a_winfo[test_id].vactive);
      CheckItem(WTest_Menu,10,a_winfo[test_id].growbox);
    end;
          
procedure       DoWinTest;
    begin
      with a_winfo[test_id] do
        begin
          CloseWindow(test_id);
          case Menu_choice of
            1:  ;
            2:  dialog := not(dialog);
            3:  goawaybox := not(goawaybox);
            4:  hscrollbar := not(hscrollbar);
            5:  vscrollbar := not(vscrollbar);
            6:  hthumb := not(hthumb);
            7:  vthumb := not(vthumb);
            8:  hactive := not(hactive);
            9:  vactive := not(vactive);
            10:  growbox := not(growbox);
          end;
          SetChecks;
          OpenWindow(a_winfo[test_id]);
          DrawItB(test_id);
        end;
        
    end;
    
procedure       DoMenuTest;
    procedure           DisMenu;
        begin
          DisableMenu(Dummy_Menu,true);
        end;
    procedure           EnMenu;
        begin
          DisableMenu(Dummy_Menu,false);
        end;
    procedure           DisItems;
        begin
          DisableItem(Dummy_menu,3,true);
          DisableItem(Dummy_menu,7,true);
          DisableItem(Dummy_menu,8,true);
        end;
    procedure           EnItems;
        begin
          DisableItem(Dummy_menu,3,false);
          DisableItem(Dummy_menu,7,false);
          DisableItem(Dummy_menu,8,false);
        end;
    procedure           CkItems;
        begin
          CheckItem(Dummy_menu,1,true);
          CheckItem(Dummy_menu,3,true);
          CheckItem(Dummy_menu,6,true);
          CheckItem(Dummy_menu,9,true);
          CheckItem(Dummy_menu,10,true);
        end;
    
    procedure           UnckItems;
        begin
          CheckItem(Dummy_menu,1,false);
          CheckItem(Dummy_menu,3,false);
          CheckItem(Dummy_menu,6,false);
          CheckItem(Dummy_menu,9,false);
          CheckItem(Dummy_menu,10,false);
        end;
    
    procedure           ChangeMarks;
        begin
          SetMark(Dummy_menu,3,true,'#');
          SetMark(Dummy_menu,9,true,'*');
        end;
    
    procedure           RestoreMarks;
        begin
          SetMark(Dummy_menu,3,false,' ');
          SetMark(Dummy_menu,9,false,'0');
        end;
        
    procedure           ClearMenu;
        begin
          EnMenu;
          EnItems;
          UnckItems;
          RestoreMarks;
        end;
        
        
    begin
      case menu_choice of
        1: ClearMenu;
        2: DisMenu;
        3: EnMenu;
        4: DisItems;
        5: EnItems;
        6: CkItems;
        7: UnckItems;
        8: ChangeMarks;
        9: RestoreMarks;
      end;
    end;
    
procedure doMenu;
    begin { doMenu }
      if menu_id in [applemenu,filemenu,editmenu,windowmenu,mtestmenu,wtestmenu,
                     dummymenu] then 
        case menu_id of
          apple_menu: doApple;
          file_menu: doFile;
          edit_menu: doEdit;
          WindowMenu : DoWindows;
          MTest_Menu: DoMenuTest;
          WTest_Menu : DoWinTest;
          dummy_menu : ;
        end
      else exit(DoMenu);
      HiliteMenu(0); 
    end; { of doMenu }

procedure HandleButton;
    begin { HandleButton }
      with event do
        begin
          screenx:= char1+ 256* char2;
          screeny:= char3+ 256* char4;
          FindWindow(screenx, screeny, whicharea, windowid);
          case whicharea of
            
            inMenubar: 
              begin
                MenuSelect(menu_id, menu_choice);
                doMenu;
              end; { case inMenubar }
            
            inDrag: 
              begin
                BringItUp(WindowID);
                DoDrag; 
              end;
            
            inGrow: DoGrow;
              
            inGoAway: 
              begin
                TrackGoAway(DoGoAway);
                if DoGoAway then DoHide;
              end;
             
            inContent: DoContent;
         
          end; { case }
        end; { with }
    end; { of HandleButton }


{ This posts some events to pull down a menu and select an item
  from it.  }
procedure SignOn;
    var
       k : integer;
       e1,e2,e3,e4 : type_event;
       
       procedure        PrintEvent      (var f : text;
                                         var e : type_event);
           begin
             writeln(f,'Evt_Kind:  ',e.evt_kind);
             writeln(f,'Char1:  ',e.char1);
             writeln(f,'Char2:  ',e.char2);
             writeln(f,'Char3:  ',e.char3);
             writeln(f,'Char4:  ',e.char4);
           end;
           
    begin
      e1.evt_kind := button_down;
      e1.char1 := 15;
      e1.char2 := 0;
      e1.char3 := 0;
      e1.char4 := 0;
      e2 := e1;
      e3 := e1;
      e4 := e1;
      e2.evt_kind := drag;
      e3.evt_kind := drag;
      e3.char3 := 17;
      e4 := e3;
      e4.evt_kind := button_up;
      
      postevent(e1);
      postevent(e2);
      for k := 1 to 10 do postevent(e3);
      postevent(e4);
      
      
      { Post um again }
      postevent(e1);
      postevent(e2);
      for k := 1 to 10 do postevent(e3);
      postevent(e4);
    end;


begin { psample }
   
   Initialize;
   
   InitMouseDriver;
   StartItUp;
   
   SetChecks;  { Initialize the values in the window test menu }
   
   InitPort(MainPort);
   SetPort(MainPort);
   
   {SignOn;}
   
   
   QuitSelected:= false;
   Repeat
      GetEvent(event);
      
      if event.evt_kind in [ButtonDown,KeyDown,UpdateEvent] then 
        case event.evt_kind of
           button_down : HandleButton;
           key_down : 
             begin
               MenuKey(menu_id, menu_choice, event);
               if menu_id<> 0 then doMenu;
             end;
           update_event : HandleUpdate(event.char1);
           
        end;
   
   Until QuitSelected;
   CloseAll;
   writeln;
   Version(VMajor,VMedium,VMinor,VStatus,VRelease);
   writeln('Version ', VMajor,'.',VMedium,'.',VMinor,VStatus,VRelease);
   PrintPort(output,mainport);
   GetPort(x);
   writeln('PortAdr:  ',x);
   x := pointerto(mainport);
   writeln('MainPort at:  ',x);
   StopDeskTop;


end. { of psample }


(*
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$   END OF FILE : TK - TK.PART3.TEXT
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

File brought to you by:

Apple Macintosh Apple II Pascal Disk Image Dumper 1.0.0 (16 May 2004)
David T Craig (Santa Fe, New Mexico, USA)
shirlgato@cybermesa.com / dcraig@cyberwolf.com

Sunday, June 20, 2004 -- 1:52:10 PM
*)

